package com.docker.drug.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.docker.common.annotation.Log;
import com.docker.common.core.controller.BaseController;
import com.docker.common.core.domain.AjaxResult;
import com.docker.common.enums.BusinessType;
import com.docker.drug.domain.DoctorDrugsOutIntermediate;
import com.docker.drug.service.IDoctorDrugsOutIntermediateService;
import com.docker.common.utils.poi.ExcelUtil;
import com.docker.common.core.page.TableDataInfo;

/**
 * 药品入库和药品中间Controller
 * 
 * @author lin
 * @date 2025-04-12
 */
@RestController
@RequestMapping("/drug/outIntermediate")
public class DoctorDrugsOutIntermediateController extends BaseController
{
    @Autowired
    private IDoctorDrugsOutIntermediateService doctorDrugsOutIntermediateService;
//    根据药品编码查询
    @GetMapping("/selectDrugCode")
    public AjaxResult selectDrugCode(String drugCode)
    {
        System.out.println("前端数据"+drugCode);
        List<DoctorDrugsOutIntermediate> list = doctorDrugsOutIntermediateService.selectDrugCode(drugCode);
        return success(list);
    }

    /**
     * 查询药品入库和药品中间列表
     */
    @PreAuthorize("@ss.hasPermi('drug:outIntermediate:list')")
    @GetMapping("/list")
    public TableDataInfo list(DoctorDrugsOutIntermediate doctorDrugsOutIntermediate)
    {
        startPage();
        List<DoctorDrugsOutIntermediate> list = doctorDrugsOutIntermediateService.selectDoctorDrugsOutIntermediateList(doctorDrugsOutIntermediate);
        return getDataTable(list);
    }

    /**
     * 导出药品入库和药品中间列表
     */
    @PreAuthorize("@ss.hasPermi('drug:outIntermediate:export')")
    @Log(title = "药品入库和药品中间", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DoctorDrugsOutIntermediate doctorDrugsOutIntermediate)
    {
        List<DoctorDrugsOutIntermediate> list = doctorDrugsOutIntermediateService.selectDoctorDrugsOutIntermediateList(doctorDrugsOutIntermediate);
        ExcelUtil<DoctorDrugsOutIntermediate> util = new ExcelUtil<DoctorDrugsOutIntermediate>(DoctorDrugsOutIntermediate.class);
        util.exportExcel(response, list, "药品入库和药品中间数据");
    }

    /**
     * 获取药品入库和药品中间详细信息
     */
    @PreAuthorize("@ss.hasPermi('drug:outIntermediate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(doctorDrugsOutIntermediateService.selectDoctorDrugsOutIntermediateById(id));
    }

    /**
     * 新增药品入库和药品中间
     */
    @PreAuthorize("@ss.hasPermi('drug:outIntermediate:add')")
    @Log(title = "药品入库和药品中间", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DoctorDrugsOutIntermediate doctorDrugsOutIntermediate)
    {
        return toAjax(doctorDrugsOutIntermediateService.insertDoctorDrugsOutIntermediate(doctorDrugsOutIntermediate));
    }

    /**
     * 修改药品入库和药品中间
     */
    @PreAuthorize("@ss.hasPermi('drug:outIntermediate:edit')")
    @Log(title = "药品入库和药品中间", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DoctorDrugsOutIntermediate doctorDrugsOutIntermediate)
    {
        return toAjax(doctorDrugsOutIntermediateService.updateDoctorDrugsOutIntermediate(doctorDrugsOutIntermediate));
    }

    /**
     * 删除药品入库和药品中间
     */
    @PreAuthorize("@ss.hasPermi('drug:outIntermediate:remove')")
    @Log(title = "药品入库和药品中间", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(doctorDrugsOutIntermediateService.deleteDoctorDrugsOutIntermediateByIds(ids));
    }
}
